import request from '@/utils/axios'
import { userList, succCode, userMenu } from './type'

enum API {
  ALLROLE_URL = '/admin/acl/role/',
  ADDROLE_URL = '/admin/acl/role/save',
  UPDATEROLE_URL = '/admin/acl/role/update',
  ALLPERMISSION_URL = '/admin/acl/permission/toAssign/',
  SETPERMISSION_URL = '/admin/acl/permission/doAssign/?',
  REMOVEROLE_URL = '/admin/acl/role/remove/',
}

export const reqAllRoleList = (page: number, size: number) =>
  request.get<any, userList>(API.ALLROLE_URL + `${page}/${size}`)
// /?roleName=${limt}  limt: string
export const reqAddOrUpdateRole = (data: any) => {
  if (data.id) {
    return request.put<any, succCode>(API.UPDATEROLE_URL, data)
  } else {
    return request.post<any, succCode>(API.ADDROLE_URL, data)
  }
}
// 获取权限
export const reqAllMenuList = (roleId: number) =>
  request.get<any, userMenu>(API.ALLPERMISSION_URL + roleId)
export const reqSetPermisstion = (roleId: number, permissionId: number[]) =>
  request.post<any, succCode>(
    API.SETPERMISSION_URL + `roleId=${roleId}&permissionId=${permissionId}`,
  )
export const reqDelect = (id: number) =>
  request.delete<any, succCode>(API.REMOVEROLE_URL + id)
